<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8" />
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/ui/global/bootstrap/css/bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/adminlte/dist/css/AdminLTE.css">
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/adminlte/dist/css/skins/_all-skins.min.css">
    <link href="https://tv.speechb.com/lib/superui/content/min/css/supershopui.common.min.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/superui/content/layx/layx.min.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/x-editable/css/bootstrap-editable.css" rel="stylesheet"/>
    <link href="https://tv.speechb.com/lib/x-editable/css/select2-bootstrap.css" rel="stylesheet"/>
    <link href="https://tv.speechb.com/lib/layui/css/layui.css" rel="stylesheet"/>
    <!--全局通用框架样式 end-->
</head>
<body>

<!-- Main content -->
<section class="content">
    <div class="row">
        <!-- BEGIN SAMPLE TABLE PORTLET-->
        <div class="col-md-12">


            <div id="toolbar" class="btn-group">
                <button id="btn_add" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
                <button id="btn_delete" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                </button>
            </div>
            <div class="table-scrollable">
                <table id="table"></table>

            </div>
        </div>
    </div>
</section>
<script src="http://tv.speechb.com/lib/superui/content/ui/global/jQuery/jquery.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="https://tv.speechb.com/lib/superui/content/ui/global/bootstrap/js/bootstrap.min.js"></script>

<script src="https://tv.speechb.com/lib/x-editable/js/bootstrap-editable.min.js"></script>

<script src="https://tv.speechb.com/lib/superui/content/min/js/supershopui.common.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/layx/layx.min.js"></script>
<script type="text/javascript" charset="utf-8" src="https://tv.speechb.com/lib/toaster/jquery.toaster.js"></script>
<script type="text/javascript" charset="utf-8" src="https://tv.speechb.com/lib/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/admin/js/editable_com.js"></script>
</body>
<script>
    $(function () {
        initBootstrapTable('/admin/orders/orders_list',[{
            checkbox: true
        }, {
            field: 'id',
            title: 'ID',
            visible: false
        }, {
            field: 'sorting',
            title: '序号',
            align: 'center',
            sortable: true,//启用排序
            width: 60,
            formatter: function (value, row, index) {
                var pageSize = $('#table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
            }
        }, {
            field: 'username',
            title: '用户名',
            align: 'center',
            width: 120,
            formatter: function (value, row, index) {
                return '<a id="' + row.id + 'username"data-type="textarea" value="' + row.username + '">' + value + '</a>';
            }
        },{
            field: 'type',
            title: '类型',
            align: 'center',
            width:60,
        },{
            field: 'counts',
            title: '总数',
            align: 'center',
            width:60,
        },{
            field: 'remark',
            title: '备注',
            align: 'center',
            width:150,
            formatter: function (value, row, index) {
                return '<a id="' + row.id + 'remark"data-type="textarea" value="' + row.remark + '">' + value + '</a>';
            }
        },{
            field: 'status',
            title: '状态',
            align: 'center',
            width:70,
            formatter:stateFormatter
        },{
            field: 'create_time',
            title: '更新日期',
            align: 'center',
            width: 180,
        }, {
            field: 'operation',
            title: '操作',
            align: 'center',
            width: 120,
            events: actionEvents,//给按钮注册事件
            formatter: actionFormatter//表格中增加按钮
        }],function (data) {
            var url = '/admin/hold_girl_book/update';
            for (var i = 0; i < data.rows.length; i++) {
                editableConfig(data.rows[i].id + "name", 'textarea', data.rows[i].id, '书籍名称更改', url);
                editableConfig(data.rows[i].id + "pager_count", 'text', data.rows[i].id, '页码更改', url);
                editableConfig(data.rows[i].id + "author", 'textarea', data.rows[i].id, '书籍作者更改', url);
                editableConfig(data.rows[i].id + "tag", 'textarea', data.rows[i].id, '标签更改', url);
                // 状态可编辑
                $('#'+data.rows[i].id + 'status').editable({
                    type:'select',
                    pk:data.rows[i].id ,
                    url:url,
                    title:'状态编辑',
                    value: data.rows[i].status,
                    placement:'left',
                    source: [
                        {value: "1", text: '正常'},
                        {value: "2", text: '禁用'},
                    ],
                    success:function(rspData,newValue) {
                        // 有返回既有错误
                        if(rspData.code<0) {
                            return rspData.data;
                        }
                    }
                });
            }
        });

        $("#btn_add").click(function(){
            layx.iframe('hold_girl_book_publish','书籍添加','/admin/hold_girl_book_publish');
        });
        batchDelete("/admin/hold_girl_book/delete_list", "是否批量删除书籍！");

    });
    function actionFormatter(value) {
        return [
            ' <a href="javascript:;" class="btn btn-icon-only purple scan "><i class="fa fa-eye "></i></a>'+
            ' <a href="javascript:;" class="btn btn-icon-only purple update "><i class="fa fa-edit "></i></a>'+
            '<a href="javascript:;" class="btn btn-icon-only red remove"> <i class="fa fa-times "></i></a>',

        ].join('');
    }
    function stateFormatter(value, row) {

        if (row.status == "1") {
            return ' <span id="'+row.id+'status" class="label label-sm label-success"> 支付 </span>';
        } else {
            return '<span id="'+row.id+'status" class="label label-sm label-danger"> 待支付 </span>';
        }

    }
    // update and delete events
    window.actionEvents = {
        'click .scan': function (e, value, row) {
            window.open("/book/detail/"+row.id);
        },
        'click .update': function (e, value, row, index) {
            layx.iframe('hold_girl_book_publish','更新书籍','/admin/hold_girl_book_publish?id='+row.id);
        },

        'click .remove': function (e, value, row) {
            if (confirm('是否删除书籍?')) {
                $.ajax({
                    url: "/admin/hold_girl_book/delete?id="+row.id,
                    type: 'delete',
                    success: function (data) {
                        console.log(data.code);
                        if(data.code == 1) {
                            $('#table').bootstrapTable('refresh');
                        } else {
                            $.toaster({ priority : "danger", title : "通知", message : "删除话术失败!" });
                        }
                    },
                    error: function () {
                        $.toaster({ priority : "danger", title : "通知", message : "删除话术失败!" });
                    }
                })
            }
        }
    };

</script>
</html>